﻿Imports System.Data.OleDb
Public Class ParentProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.Params("TuteeID") = User.Identity.Name Then
            btnAcceptRequest.Visible = False
        Else
            btnAcceptRequest.Visible = True
        End If
       

    End Sub

    Protected Sub btnAcceptRequest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAcceptRequest.Click
        Dim SqlString As String
        Dim SqlString1 As String
        Dim SqlString2 As String
        Dim cmd As OleDbCommand
        Dim cmd1 As OleDbCommand
        Dim cmd2 As OleDbCommand

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TutorsConnectionString").ConnectionString)
        SqlString = "SELECT * FROM tblParents WHERE TuteeID=@f1"
        cmd = New OleDbCommand(SqlString, oleDbConn)
        SqlString1 = "SELECT * FROM tblTutorProfile WHERE TutorUserName=@f2"
        cmd1 = New OleDbCommand(SqlString1, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd1.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", Request.Params("TuteeID"))
        cmd1.Parameters.AddWithValue("@f2", User.Identity.Name)
        oleDbConn.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader()
        Dim dr1 As OleDbDataReader = cmd1.ExecuteReader()

        SqlString2 = "INSERT into tblContract (Parent_fkID, Tutor_fkID) VALUES(@f1, @f2)"
        cmd2 = New OleDbCommand(SqlString2, oleDbConn)
        dr.Read()
        cmd2.Parameters.AddWithValue("@f1", dr("ID"))
        dr.Close()
        dr1.Read()
        cmd2.Parameters.AddWithValue("@f2", dr1("ID"))
        
        cmd2.ExecuteNonQuery()
        dr.Close()
        cmd.Dispose()
        cmd1.Dispose()
        cmd2.Dispose()
        oleDbConn.Close()
        oleDbConn.Dispose()
        MsgBox("You have accepted this request successfully")
    End Sub
End Class